package com.ctop.evoa.webservice.config;

import com.ctop.evoa.webservice.interceptor.AuthInterceptor;
import com.ctop.evoa.webservice.service.DepartmentService;
import com.ctop.evoa.webservice.service.UserService;
import com.ctop.evoa.webservice.service.impl.DepartmentServiceImpl;
import com.ctop.evoa.webservice.service.impl.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;


/**
 * @Author : zhuwl
 * @Description : description
 * @Date Created by 上午 11:11 on 2018/1/23 0023.
 */
@Configuration
public class WebServiceConfig {

    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/test/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public UserService userService() {
        return new UserServiceImpl();
    }

    @Bean
    public DepartmentService departmentService() {
        return new DepartmentServiceImpl();
    }

    @Bean
    public Endpoint userEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
        //添加权限验证
        endpoint.getInInterceptors().add(new AuthInterceptor());
        //调用路径
        endpoint.publish("/user");
        return endpoint;
    }

    @Bean
    public Endpoint departmentEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), departmentService());
        //添加权限验证
        endpoint.getInInterceptors().add(new AuthInterceptor());
        //调用路径
        endpoint.publish("/department");
        return endpoint;
    }
}
